<template>
	<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
		<div class="navbar-header">
			<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
			<a class="navbar-brand" id="loginLogo" href="#"></a>
		</div>
		<div id="navbar" class="collapse navbar-collapse">
			<ul class="nav navbar-nav">
				<li class="active">
					<a href="javascript:;">首页</a>
				</li>
				<li>
					<a href="javascript:;">机构管理</a>
				</li>
				<li>
					<a href="javascript:;">报备管理</a>
				</li>
			</ul>
			<div class="login-settings">
				<a href="javascript:;" class="clearfix">
					<div class="loginImg"></div>
					<div class="loginName">{{accountName}}</div>
					<i class="fa fa-caret-down"></i>
				</a>
				<ul class="login-settings-list">
					<li>
						<a href="javascript:;" @click="passwordUpdate()"><i class="fa fa-gear"></i>密码修改</a>
					</li>
					<li>
						<a href="javascript:;" @click="loginExit"><i class="fa fa-power-off"></i>退出</a>
					</li>
				</ul>
				<div class="triangle-up"><span class="triangle-up-sm"></span></div>
			</div>
		</div>
		<updatePassword></updatePassword>
	</nav>
</template>
<script>
	import updatePassword from './updatePassword.vue'
	export default {
		name: 'top',
		data() {
			return {
				accountName: window.localStorage.getItem("4_userName"),
				userId:window.localStorage.getItem("4_userId")
			}
		},
		components:{updatePassword},
		mounted: function() {
			this.loginSettingInit();
			this.getCompanyLogo();
		},
		methods: {
			updatePwd(){
				alert(0);
			},
			passwordUpdate(){
				var _self =this;
				$('#updatePassword').modal('show');
				//_self.isShow = true;
			},
			getCompanyLogo: function () {
	                var _self = this;
	                var url = _self.utilHelper.apiUrl + "/api/getLogo";
	                var params = {"params":{'logoType': '7'}}
	                _self.$http.post(url, params).then((response) => {
	                    var data = response.body;
	                    if (data.result=='1') {
	                        //_self.logoUrl = data.resData;
	                        $("#loginLogo").addClass("top_logo");
	                        $("#loginLogo").css("backgroundImage","url("+data.resData.logoUrl+")");
	                    }else{
	                    	$("#loginLogo").addClass("top_logo");
	                    }
	                })
	            },
			loginSettingInit() {
				$(function() {
					$(document).off("click");
					$(document).on('click', function(event) {
						var $this = $(event.target).parents('.login-settings');
						if($this.length == 0) {
							$('.login-settings').removeClass("active");
						} else {
							if($this.hasClass("active")) {
								$this.removeClass("active");
							} else {
								$this.addClass("active");
							}
						}
					});
				})
			},
			settingShow() {
				$(".dropdown-toggle").dropdown('toggle');
			},
			loginExit() {
				var _self = this;
				var body = {};
				var params = {};
				body.params=params;
				var url = _self.utilHelper.apiUrl + "/api/loginOut";
				_self.$http.post(url,body).then((response) => {
					var data = response.body.resData;
					var result = data.result;
					var resData = data.resultMsg;
					layer.msg(resData, {
						time: 1000
					}, function() {
						window.localStorage.setItem("4_isLogin", null);
						window.localStorage.setItem("4_userId", null);
						_self.$router.replace({
							path: '/login'
						})
					});
				}, (response) => {});
			}
		}
	}
	function update_pass(){
	if($("#oldPassword").val()==null||$("#oldPassword").val()==""){
		layer.alert("请输入原密码");
		return;
	}
	
	if($("#newPassword").val()==null||$("#newPassword").val()==""){
		layer.alert("请输入新密码");
		return;
	}

    var reg = /^[a-zA-Z0-9~!@#$%^&*()-_+=`{}\[\]:;"'<>?,.\/\\]{8,20}$/;
    if(!reg.test($("#newPassword").val())){
        layer.msg("密码为长度8-20位的数字、字母、下划线或常用字符(`~!@#$%^&*()-_+={}[]:;\"'<>?,.\/)",{
            time: 3000
        });
        return;
    }
	if($("#cofirmPassword").val()==null||$("#cofirmPassword").val()==""){
		layer.alert("请确认新密码");
		return;
	}
	if($("#newPassword").val() != $("#cofirmPassword").val()){
        layer.alert("两次密码输入不一致");
        return;
    }
	var data={
			oldPassword:$("#oldPassword").val(),
			newPassword:$("#newPassword").val(),
			cofirmPassword:$("#cofirmPassword").val(),
			userId:12
	};
	$.ajax({
		type: "POST",
        url: "${request.contextPath}/assistant/member/updatePasswordDetail.do",
        data: data,
        dataType: "json",
        success:function(rs){
			/*if(rs.head.success){
				layer.alert(rs.head.message, {
	        	    skin: 'layui-layer-molv' //样式类名
	        	    ,closeBtn: 0
	        	}, function(){
	        		 //刷新
	        		 if(rs.head.success){
	        			 location.href="${request.contextPath}/user/loginOut.do";
	        		 }
	            	
	        	});
			}else{
				layer.alert(rs.head.message);
			}*/
	        
        },
	});
}
</script>
<style>
</style>